This is the complete Global code from the game titled “Ray’s World Builder Demo.” Following it, the code is broken down into individual sections, with explanations of each section.
PRINT{The lamp is now lit, and gives off a steady light.}
IF{DARK.1=SCENE@}THEN
MOVE{DARK.1}TO{STORAGE@}
EXIT
EXIT
PRINT{You only have a few matches left. You should save them for something more important.}
EXIT
IF{TEXT$=POTION}THEN
PRINT{You're supposed to drink it, doofus!}
EXIT
PRINT{That doesn't work.}
EXIT
IF{TEXT$=HIT}OR{TEXT$=BREAK}THEN
PRINT{You can't break that.}
EXIT
IF{TEXT$=SHOOT}THEN
PRINT{You shouldn't shoot that.}
EXIT
IF{TEXT$=READ}THEN
PRINT{....................................}
IF{TEXT$=CLIPPING}THEN
IF{CLIPPING=PLAYER@}THEN
MOVE{CLIPPING.2}TO{SCENE@}
PRINT{Click on the clipping when you are through reading it.}
EXIT
PRINT{You don't have the clipping.}
EXIT
PRINT{Read what?}
EXIT
IF{TEXT$=EAT}OR{TEXT$=TASTE}THEN
PRINT{..................................}
PRINT{Eat what?}
EXIT
IF{TEXT$=$}OR{TEXT$=COUNT MONEY}THEN
PRINT{..................................}
IF{CASH>PLAYER@}OR{X1#<1}THEN
PRINT{You don't have any money.}
EXIT
IF{X1#=10}THEN
PRINT{You have $10.}
EXIT
IF{X1#=9}THEN
PRINT{You have $9.}
EXIT
IF{X1#=8}THEN
PRINT{You have $8.}
EXIT
IF{X1#=7}THEN
PRINT{You have $7.}
EXIT
IF{X1#=6}THEN
PRINT{You have $6.}
EXIT
IF{X1#=5}THEN
PRINT{You have $5.}
EXIT
IF{X1#=4}THEN
PRINT{You have $4.}
EXIT
IF{X1#=3}THEN
PRINT{You have $3.}
EXIT
IF{X1#=2}THEN
PRINT{You have $2.}
EXIT
IF{X1#=1}THEN
PRINT{You have $1.}
EXIT
EXIT
IF{TEXT$=DRINK}THEN
PRINT{..................................}
IF{TEXT$=POTION}THEN
IF{POTION>PLAYER@}THEN
PRINT{You don't have a potion.}
EXIT
MOVE{POTION}TO{STORAGE@}
LET{PHYS.STR.BAS#=255}
LET{PHYS.STR.CUR#=255}
PRINT{You swallow the potion in one gulp, and a strange sensation comes over you. Suddenly you feel stronger than ever!}
EXIT
PRINT{Drink what?}
EXIT
IF{TEXT$=THANKS}OR{TEXT$=THANK YOU}THEN
PRINT{"You're welcome!"}
EXIT
IF{TEXT$=HAKO}THEN
PRINT{Nothing happens.}
EXIT
IF{TEXT$=TURN}OR{TEXT$=TWIST}THEN
PRINT{You can't turn that.}
EXIT
IF{TEXT$=DIG}THEN
PRINT{You can't dig here.}
EXIT
IF{TEXT$=INSPECT}OR{TEXT$=EXAMINE}THEN
PRINT{Click on the things you want to examine.}
EXIT
IF{CLICK$=LAMP}THEN
PRINT{..................................}
IF{L1#=1}THEN
PRINT{The lamp is lit.}
END
IF{L1#<1}THEN
PRINT{The lamp is not lit.}
END
END
IF{CLICK$=CLIPPING.2}THEN
MOVE{CLIPPING.2}TO{STORAGE@}
EXIT
***************End of code*************************
The Global code is the place to put default responses to any of the possible actions the player can do in the game. It is also useful for code that applies to all scenes in the game, as opposed to scene code, which is operative only in one specific scene.
The statement below prints a default response when the player tries to move, push, or pull anything not covered by scene code:
IF{TEXT$=MOVE}OR{TEXT$=PUSH}OR{TEXT$=PULL}THEN
PRINT{You can't move that.}
EXIT
This statement prints a default response whenever the player searches and the search is not handled by scene code:
IF{TEXT$=SEARCH}THEN
PRINT{You find nothing unusual.}
EXIT
This statement prints a default response when the player tries to open something that is not covered by the scene code:
IF{TEXT$=OPEN}THEN
PRINT{You can't open that.}
EXIT
This statement prints a default response when the player tries to close something that is not covered by the scene code:
IF{TEXT$=CLOSE}THEN
PRINT{You can't close that.}
EXIT
This statement prints a default response when the player tries to enter something that is not covered by the scene code:
IF{TEXT$=ENTER}THEN
PRINT{You can't enter anything here.}
EXIT
This statement prints a default response when the player tries to exit something that is not covered by the scene code:
IF{TEXT$=EXIT}THEN
PRINT{You can't exit anything here.}
EXIT
This statement prints a default response when the player enters “up” or “climb” and those command are not handled by the scene code:
IF{TEXT$=UP}OR{TEXT$=CLIMB}THEN
PRINT{You can't go up here.}
EXIT
This statement prints a default response when the player enters “down” and that command is not handled by the scene code:
IF{TEXT$=DOWN}THEN
PRINT{You can't go down here.}
EXIT
This statement prints a default response when the player enters “use” and that command are not handled by the scene code. It also includes nested statement for specific things the player wants to use, such as matches or the potion. These are items that can be used in any scene, so the Global code is a good place to handle these actions:
PRINT{The lamp is now lit, and gives off a steady light.}
IF{DARK.1=SCENE@}THEN
MOVE{DARK.1}TO{STORAGE@}
EXIT
EXIT
PRINT{You only have a few matches left. You should save them for something more important.}
EXIT
IF{TEXT$=POTION}THEN
PRINT{You're supposed to drink it, doofus!}
EXIT
PRINT{That doesn't work.}
EXIT
>>>In the section above, the first statement tests for entry of the word “use.” The first nested statement tests for the word “match,” which also applies to “matches.” Another statement nested in that one checks to see if the player has the matches, and if not, prints text telling the player that he doesn’t have a match. If the player does have the matches, then another nested statement checks to see if the player has the lamp, or the lamp is in the scene, or the immobile object LAMP.1 is in the scene. (LAMP.1 depicts the lamp setting on the cabinet before the player takes it.) If any of these conditions is true, then L1# is set to one, and text is printed telling the player that the lamp is now lit. Finally, a statement checks to see if the object DARK.1 is in the current scene, and if so, moves it to storage so that the will be visible.
If the player does not have the lamp, and the lamp is not in the scene, and LAMP.1 is not in the scene, then the “lamp” statement is ignored, and text is printed telling the player to save his matches.
The last nested statement tests for entry of the word “potion.” If the player tries to “use” the potion, this statement tells him to drink it.
If the nested statements are not true, they are ignored, and text is printed telling the player “That doesn’t work.” This is the default response given anytime the player tries to use something not covered by scene code.<<<
This statement prints the default response when the player tries to hit or break something not handled by scene code:
IF{TEXT$=HIT}OR{TEXT$=BREAK}THEN
PRINT{You can't break that.}
EXIT
This statement prints the default response when the player tries to shoot something not handled by scene code:
IF{TEXT$=SHOOT}THEN
PRINT{You shouldn't shoot that.}
EXIT
This statement handles the default response for the verb “read.” A nested statement handles any entry of both “read” and “clipping.” Since the clipping is a mobile object, it can be carried and read at anytime, so the Global code is the place for this:
IF{TEXT$=READ}THEN
PRINT{....................................}
IF{TEXT$=CLIPPING}THEN
IF{CLIPPING=PLAYER@}THEN
MOVE{CLIPPING.2}TO{SCENE@}
PRINT{Click on the clipping when you are through reading it.}
EXIT
PRINT{You don't have the clipping.}
EXIT
PRINT{Read what?}
EXIT
>>>In the code above, if the player enters “read”, a nested statement checks to see if he has also entered “clipping.” If so, then another nested statement checks to see if the player has the clipping. If so, then a closeup drawing (CLIPPING.2} of the clipping is moved to the scene, and text is printed telling the player to click on it when finished.
If the player doesn’t have the clipping, text is printed telling him so. If “clipping” has not been entered, then the default response is printed.<<<
The code below handles any use of the word “eat” that is not covered by the scene code. Although this game does not contain anything for the player to eat, some code is included to show you how it is done.
A nested statement checks to see if the word “food” has also been entered, and if so, then another statement checks to see if the player has the food. If this is also true, then the food is moved to storage and text is printed telling the player that he is no longer hungry. Normally, a variable would be used to keep track of the player’s hunger, and that variable would be decreased each time the player comes into a scene. Then, when the player eats, the variable would be increased:
IF{TEXT$=EAT}OR{TEXT$=TASTE}THEN
PRINT{..................................}
IF{TEXT$=FOOD}THEN
IF{FOOD=PLAYER@}THEN
PRINT{The food in your pack fills your hunger.}
MOVE{FOOD}TO{STORAGE@}
LET{H1#=100}
EXIT
PRINT{You don’t have any food.}
EXIT
PRINT{Eat what?}
EXIT
In the section below, the variable X1# is used to keep track of the player’s money. Anytime the player enters a dollar sign or the word “count,” this section will print text telling the player how much money he has. A series of nested statements is used to determine the exact value of X1#, and to print the amount of the player’s money. The first nested statement checks to see if X1# is less than one, OR if the “cash” object is not in the player’s possession. If either is true, then it tells the player that he has no money:
IF{TEXT$=$}OR{TEXT$=COUNT MONEY}THEN
PRINT{..................................}
IF{CASH>PLAYER@}OR{X1#<1}THEN
PRINT{You don't have any money.}
EXIT
IF{X1#=10}THEN
PRINT{You have $10.}
EXIT
IF{X1#=9}THEN
PRINT{You have $9.}
EXIT
IF{X1#=8}THEN
PRINT{You have $8.}
EXIT
IF{X1#=7}THEN
PRINT{You have $7.}
EXIT
IF{X1#=6}THEN
PRINT{You have $6.}
EXIT
IF{X1#=5}THEN
PRINT{You have $5.}
EXIT
IF{X1#=4}THEN
PRINT{You have $4.}
EXIT
IF{X1#=3}THEN
PRINT{You have $3.}
EXIT
IF{X1#=2}THEN
PRINT{You have $2.}
EXIT
IF{X1#=1}THEN
PRINT{You have $1.}
EXIT
EXIT
>>>As you can see by the example above, determining how much money the player has can use a lot of code space. That is why I usually limit the player’s money to $10. If you wish, there is another way to do this, which allows for unlimited amounts while using less space. However, it uses somewhat more awkward format:
>>>In this alternate method, using PRINT and enclosing the name of the variable will cause the program to print the value of that variable, whatever it may be.<<<
This statement prints the default response when the player tries to drink something not handled by scene code. And the nested statement handles the player’s request to drink the potion:
IF{TEXT$=DRINK}THEN
PRINT{..................................}
IF{TEXT$=POTION}THEN
IF{POTION>PLAYER@}THEN
PRINT{You don't have a potion.}
EXIT
MOVE{POTION}TO{STORAGE@}
LET{PHYS.STR.BAS#=255}
LET{PHYS.STR.CUR#=255}
PRINT{You swallow the potion in one gulp, and a strange sensation comes over you. Suddenly you feel stronger than ever!}
EXIT
PRINT{Drink what?}
EXIT
>>>In the code above, if the player enters “drink,” a nested statement checks to see if he has also entered “potion.” If so, then another statement checks to see if the player has the potion. If not, it prints some text telling him he doesn’t have it. If the player does have the potion, then the potion is moved to storage and the player’s BASE strength and CURRENT strength are increased to 255, the maximum amount. If you only increase the player’s current strength, it will be a temporary enhancement that will soon wear off, returning his strength to its previous level. By increasing the player’s base strength too, we can insure that the change will be permanent, unless some code changes it again.<<<
This statement prints the default response when the player enters “thanks” or “thank you.” Sometimes players will do this when another creature in the game gives them something:
IF{TEXT$=THANKS}OR{TEXT$=THANK YOU}THEN
PRINT{"You're welcome!"}
EXIT
This statement prints the default response when the player enters the magic word (HAKO) if it is not handled by scene code:
IF{TEXT$=HAKO}THEN
PRINT{Nothing happens.}
EXIT
This statement prints the default response when the player tries to twist or turn something not handled by scene code:
IF{TEXT$=TURN}OR{TEXT$=TWIST}THEN
PRINT{You can't turn that.}
EXIT
This statement prints the default response when the player tries to dig in a place where it is not handled by scene code. Although this game has no places where the player is likely to try to dig, most games do, so this default should be a part of almost every game:
IF{TEXT$=DIG}THEN
PRINT{You can't dig here.}
EXIT
This statement prints the default response when the player enters “examine” or “inspect:”
IF{TEXT$=INSPECT}OR{TEXT$=EXAMINE}THEN
PRINT{Click on the things you want to examine.}
EXIT
Since the lamp object has a variable condition, meaning it can be lit or not lit, and it is a mobile object, we need some way of telling the player whether it is lit anytime the player picks it up by clicking on it. The code below handles this:
IF{CLICK$=LAMP}THEN
PRINT{..................................}
IF{L1#=1}THEN
PRINT{The lamp is lit.}
END
IF{L1#<1}THEN
PRINT{The lamp is not lit.}
END
END
When the player reads the clipping, a closeup drawing (CLIPPING.2) is moved to the scene. Since the player can read the clipping at any scene, the code to move this drawing back to storage is also in the Global code: